//: src/com/silvtar/sync/controller/Sync.java
/* 
 * Created by 朴晟宁 <piaosn@gmail.com> on 4/21/2013. 
 * Copyright (c) 2013 朴晟宁. All rights reserved.
 * 
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program;
 * 
 * *********************************************************************
 * 
 * Modify History:
 * Date        Version    Description
 * 4/24/2013   0.1        Create The Class. The class is only a entry now.
 *                        
 */

package com.silvtar.sync.controller;

import java.net.Socket;

import com.silvtar.io.StreamToolkit;
import com.silvtar.net.NetPack;
import com.silvtar.sync.model.SSException;
import com.silvtar.sync.model.SSTree;

/**
 * 同步类。软件的同步动作从这里开始。
 * 
 * @author 朴晟宁/Silvtar
 * @author piaosn@gmail.com
 * @version 0.1
 */
public class Sync {

    int           commandPort = 20681;
    String        ipAddr_S    = "127.0.0.1";
    String        localRoot   = "/Users/silvtar/Develop/FileSyncer/test/local";

    Socket        socket;
    StreamToolkit commander;

    public Sync() {

        socket = NetPack.connect(ipAddr_S, commandPort);
        commander = new StreamToolkit(socket);

    }

    public void syncNow() {
        commander.writeUTF("[Start Sync]");
        if (commander.readUTF().equals("[Start Sync Recieved]")) {
            
            SSTree localTree = new SSTree(localRoot);
            commander.writeObject(localTree);

            commander.writeUTF("[FTP Already opened]");
            commander.writeUTF("/remote");
        }
    }
}
